/**
 * 用户管理（添加|修改）userOption.js
 * 版本号： v1.0.0
 */
$(function(){
    $("#previewBtn").click(function () {
        // layer.open({
        //     title: "地图",
        //     type: 2,
        //     area: ['400px', '400px'],
        //     content: ""
        // });


        var fileValue = $("#uploadfile").filebox('getValue');
        var file = $("#uploadfile");
        var url = $('#url').val();
        var imgDiv = $('#previewBtn');
        if(url != "" && url != null){
            $('.galpop').galpop();
            $("#galpop-content img").attr("src",url);
        }else{
            if(fileValue != ""){
                imgDiv.attr('src',fileValue);

            }else{
                $.messager.show({ title:'提示', msg: '请选择上传附件！', timeout:3000, showType:"slide" });
                return;
            }
        }
    });
    //上传操作
    $('#uploadBtn').bind('click', function(){
        uploadFile('uploadBtn','uploadfile','fileName','fileId','url','size','fix','md5','showImg');
    })

    //图片回显
    var fileId = $('#fileId').val();
    if(fileId != null && fileId != ""){
        $.ajax({
            url: CONTEXT_PATH + "/commonFile/getFileUrlById.do?id=" + fileId,
            type: "get",
            success: function (data) {
                var url = data.message;
                var imgDiv = $('#showImg');
                if(url != "" && url != null){
                    imgDiv.attr('src',url);
                }
            }
        });
    }

    //文件选择改变后调整
    $('#uploadfile').filebox({
        onChange:function(n,o){
            $('#uploadBtn').linkbutton('enable');
        }
    })

    //操作按钮点击
    $('#optionUserInformation').bind('click', function(){
        doOptionUserMethod();
    })

    //退出按钮事件
    $('#exitUserInformation').bind('click', function(){
        window.parent.toCloseSelected();
    })

    //修改时填入文件名称
    var compLogoName = $('#fileName').val();
    if(compLogoName != null && compLogoName != ""){
        $('#uploadfile').filebox({prompt:compLogoName});
    }
});


/**
 * 执行保存操作方法
 */
function doOptionUserMethod(){
    var params = $("#operate_form").serialize();
    $("#operate_form").form("submit",{
        cache:false,
        data: params,
        url: CONTEXT_PATH + "/user/insertUserInformation.do",
        onSubmit:function() {
            // getCheckedIds();
            var flag = $(this).form("validate");
            if(flag){
                preventSubmit(null, "commitBtn");
            }
            return flag;
        },
        success:function(data) {
             var obj = JSON.parse(data);
             messager(obj);
             setTimeout(function () {
                 window.parent.toCloseSelected();
             },"3000");
        }
    });

    // var MainTab = $('#MainTab');
    // var tab = MainTab.tabs("getSelected");
    // var index = MainTab.tabs("getTabIndex", tab)
    // MainTab.tabs("close",index);
}


/**
 * 获得所有选取的Id值
 */
function getCheckedIds(){
    var nodes = $("#roleCheckbox").tree('getChecked');
    //设置所勾选的菜单权限ID，并给页面的menuIds赋值
    var roleIds = "";
    var ids =[];
    for(node in nodes){
        ids.push(nodes[node].id)
    }
    roleIds = ids.join(",");
    $("#roleIds").val(roleIds);
}

